home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / pascal / xlibpas.zip / DEMO2.PAS < prev    next >
Pascal/Delphi Source File  |  1993-10-21  |  5KB  |  155 lines

  1. {*************************************************************************
  2.  
  3. DEMO 2
  4.  
  5. Demonstrates the speed difference between compiled bitmap,  conventional
  6. masked planar bitmap, and video bitmap blits.
  7.  
  8. **************************************************************************}
  9.  
  10.  
  11. Program Demo2;
  12.  
  13. Uses
  14.     Crt, Xlib;
  15.  
  16. const
  17.     turtle : array[0..601] of byte =
  18.     ( 20,30,
  19.         8,14, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  20.         8, 2,14, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  21.         8, 2, 2, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22.         8, 0, 2,14, 0, 0,14,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  23.         8, 0, 2, 5, 0, 4, 4, 4, 4,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  24.         8, 0, 2, 2, 4, 4, 0, 4, 4, 0, 4,14, 0, 0, 0, 0, 0, 0, 0, 0,
  25.         0, 0, 2, 4, 4, 4, 0, 4, 4, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
  26.         0, 0, 2, 4, 4, 4, 0, 0, 0, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
  27.         0, 0, 0, 0, 4, 0, 4, 4, 4, 0, 0, 0, 4, 0, 0, 2, 2, 0, 0, 0,
  28.         0, 0, 0, 4, 0, 4, 4, 4, 0, 4, 4, 4, 0,14, 0, 0, 2, 2, 0, 0,
  29.         0, 0, 0, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 4, 2, 2, 2, 2, 0, 0,
  30.         0, 0, 0, 4, 4, 4, 0, 4, 4, 0, 4, 4, 0, 4,14, 2, 2, 2, 0, 0,
  31.         0, 0, 0, 4, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 0, 2, 2, 0, 0, 0,
  32.         0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4,14, 2, 0, 0, 0, 0,
  33.         0, 0, 2, 2, 0, 4, 4, 4, 4, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 0,
  34.         2, 2, 2, 2, 4, 0, 0, 4, 4, 0, 4, 4, 0, 4,14, 0, 0, 0, 0, 0,
  35.         0, 2, 2, 0, 4, 4, 4, 0, 0, 4, 4, 0, 4, 0, 2, 0, 0, 0, 0, 0,
  36.         0, 0, 0, 0, 0, 4, 4, 0, 4, 4, 4, 0, 4, 4, 2,14, 0, 0, 0, 0,
  37.         0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 4, 0, 2, 2,14,14, 0, 0,
  38.         0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 4, 4, 2, 2, 2, 2, 2,14, 0,
  39.         0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 5,14, 0,
  40.         0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 2, 2, 0, 0, 2, 2, 2, 0, 2,14,
  41.         0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2,14,
  42.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2,
  43.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 0,
  44.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  45.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  46.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  47.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
  48.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  49.  
  50.  
  51. var
  52.     newfnt, pbm, vbm : pointer;
  53.  
  54.  
  55. Function AllocatedSprite( width, height, logicalwidth : integer; var bitmap ) : pointer;
  56. var
  57.     result : pointer;
  58.     size : integer;
  59. begin
  60.     getmem(pbm,width * height + 2);
  61.     xbmtopbm(bitmap,pbm^);
  62.     size := XSizeOfCBitmap( logicalwidth, bitmap );
  63.     getmem( result, size );
  64.     XCompileBitmap( logicalwidth, bitmap, result^ );
  65.     AllocatedSprite := result;
  66. end;
  67.  
  68. Procedure loaduserfonts;
  69. var
  70.     f : file;
  71.     i : integer;
  72. begin
  73.     assign(f,'d:\bp\xlib\smalthin.fnt');
  74.     reset(f,1);
  75.     getmem(newfnt,filesize(f));
  76.     blockread(f,newfnt^,filesize(f));
  77.     close(f);
  78.     xtextinit;
  79.     xregisteruserfont(newfnt^);
  80.     xsetfont(2);
  81. end;
  82.  
  83. procedure main;
  84. var
  85.     i,j,k : integer;
  86.     ratio,ratio2 : real;
  87.     pbmt0, pbmt1, vbmt0, vbmt1, cbmt0, cbmt1, vbmticks,pbmticks,cbmticks : longint;
  88.     TurtleSprite : pointer;
  89.     timer : longint absolute $0040:$006C;
  90. begin
  91.     xsetmode(XMODE320x240,360);
  92.     TurtleSprite := AllocatedSprite(20, 30, 90,turtle);
  93.  
  94.     vbm := xmakevbm(turtle,NonVisualOffs);
  95.     loaduserfonts;
  96.     xprintf(0,0,0,14,'This is a demo to show the speed difference between');
  97.     xprintf(0,8,0,14,'compiled, planar and video bitmaps.  The bitmap:');
  98.     xputcbitmap(140, 18, 0, TurtleSprite^);
  99.     xprintf(0,48,0,14,'This demo uses the NON CLIPPED, MASKED versions of');
  100.     xprintf(0,56,0,14,'       ''PBM'' and ''VBM'' put functions');
  101.     xprintf(0,78,0,14,'Press a key to start with PLANAR BITMAP demo');
  102.     readkey;
  103.     xrectfill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
  104.     pbmt0 := timer;
  105.     for k:=0 to 10 do
  106.         for j:=0 to (ScrnPhysicalHeight div 30)-1 do
  107.             for i:=0 to (ScrnPhysicalPixelWidth div 20)-1 do
  108.                 xputmaskedpbm(i*20, j*30, 0, pbm^);
  109.     pbmt1 := timer;
  110.     pbmticks := abs(pbmt1-pbmt0);
  111.  
  112.  
  113.     xprintf(0,0,0,14,'Press a key to start with the VIDEO BITMAP demo');
  114.  
  115.     readkey;
  116.     xrectfill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
  117.     vbmt0 := timer;
  118.     for k:=0 to 10 do
  119.         for j:=0 to (ScrnPhysicalHeight div 30)-1 do
  120.             for i:=0 to (ScrnPhysicalPixelWidth div 20)-1 do
  121.                 xputmaskedvbm(i*20, j*30, 0, vbm^);
  122.     vbmt1 := timer;
  123.     vbmticks := abs(vbmt1-vbmt0);
  124.     xprintf(0,0,0,14,'Now Press a key to start with COMPILED BITMAP demo');
  125.     readkey;
  126.     xrectfill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
  127.     cbmt0 := timer;
  128.     for k:=0 to 10 do
  129.         for j:=0 to (ScrnPhysicalHeight div 30)-1 do
  130.             for i:=0 to (ScrnPhysicalPixelWidth div 20)-1 do
  131.                 xputcbitmap(i*20, j*30, 0, TurtleSprite^);
  132.     cbmt1 := timer;
  133.     cbmticks := abs( cbmt1-cbmt0);
  134.     ratio := pbmticks/cbmticks;
  135.     ratio2 := vbmticks/cbmticks;
  136.     {xsetfont(1);
  137.     xprintf(0,ScrnPhysicalHeight-30,0,14,'s/100 PBM=%ld VBM=%ld CBM=%ld - %4.1lf:%4.1lf:1'
  138.     ,pbmticks,vbmticks,cbmticks,ratio,ratio2);}
  139.     {xsetfont(2);
  140.     xprintf(0,ScrnPhysicalHeight-16,0,14,'Timing is rough but still,  quite impressive ! ');
  141.     xprintf(0,ScrnPhysicalHeight-8,0,14,'Clipping slows things down considerably. ');}
  142.     xtextmode;
  143.     writeln('Planar Bitmaps   = ',pbmticks);
  144.     writeln('Video Bitmaps    = ',vbmticks);
  145.     writeln('Compiled Bitmaps = ',cbmticks);
  146.     writeln;
  147.     writeln('PBM/CBM          = ',ratio:8:10);
  148.     writeln('VBM/CBM          = ',ratio2:8:10);
  149.     readkey;
  150. end;
  151.  
  152. begin
  153.     main;
  154. end.
  155.